//
//  AppDelegate.m
//  UI08_导航控制器
//
//  Created by Scott on 15/4/28.
//  Copyright (c) 2015年 www.lanou3g.com 蓝欧3G. All rights reserved.
//

#import "AppDelegate.h"
#import "MainViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
#pragma mark - UINavigationController
/**
 * @ brief UINavigationController: 导航控制器, 是iOS中最常用的多视图控制器之一, 它用来管理多个视图控制器
 *
 * 导航控制器可以认为是管理控制器的控制器, 主要管理有层级关系的控制器
 *
 * @ 创建 
    UINavigationController继承于UIViewController, 以栈的方式管理所控制的视图控制器, 至少要有一个被管理的视图控制器, 这个控制器称作导航控制器的根视图控制器
 *   
 *   任何继承自UIViewController(多态)都可以作为根控制器
 *
 * @ 工作原理 
    UINavigationController通过栈的方式管理控制器的切换, 控制入栈和出栈来展示各个视图控制器
    
 *   UINavigationController的ContentView里始终显示栈顶控制器的view.
 *   viewControllers 属性存储了栈中的所有被管理的控制器
 *   navigationController 属性, 父类中的属性, 每个在栈中的控制器, 都能通过此属性, 获取自己所在的UINavigationController对象
 
 
 * @ 入栈和出栈
 *  pushViewController:animated  进入下一个视图控制器
    popViewControllerAnimated    返回上一个视图控制器
    popToViewController:animated: 返回到指定的视图控制器
    popToRootViewControllerAnimated: 返回到根视图控制器

 * @ 常用的属性
    viewControllers 所有处于栈中的控制器
    topViewController 位于栈顶的控制器
    visibleViewController 当前正在显示的控制器
    navigationBar 导航条
 */
    
    
#pragma mark ** 创建UINavigationController 对象
    /* 1. 创建ViewController对象 */
    MainViewController *main = [[MainViewController alloc] init];
    
    /* 2. 创建UINagationController对象, 同时作为self.windows的根视图控制器 
     *  navigationController创建的时候需要给它指定一个默认显示的viewController
     */
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:main];
    NSLog(@"%@", navi);
    
    self.window.rootViewController = navi;
    
    [navi release];
    [main release];
    [_window release];
    return YES;
}

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
